package com.itheima.pinda.impl.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.entity.pojo.base.PdGoodsType;
import com.itheima.pinda.feign.service.common.PdGoodsTypeService;
import com.itheima.pinda.mapper.base.PdGoodsTypeMapper;
import com.itheima.pinda.utils.CustomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 货物类型表 服务实现类
 * </p>
 *
 * @author xy
 * @since 2021-11-08
 */
@Service
@Transactional
public class PdGoodsTypeServiceImpl extends ServiceImpl<PdGoodsTypeMapper, PdGoodsType> implements PdGoodsTypeService {

    @Autowired
    private CustomIdGenerator idGenerator;

    @Override
    public PdGoodsType saveGoodsType(PdGoodsType goodsType) {
        goodsType.setId(idGenerator.nextId(goodsType)+"");
        super.baseMapper.insert(goodsType);
        return goodsType;
    }

    @Override
    public List<PdGoodsType> findAll() {
        QueryWrapper<PdGoodsType> wrapper = new QueryWrapper<PdGoodsType>();
        wrapper.eq("status",1);
        List<PdGoodsType> pdGoodsTypes = super.baseMapper.selectList(wrapper);
//        System.out.println(pdGoodsTypes);
       return pdGoodsTypes;
    }

    @Override
    public PdGoodsType findById(String gid) {
        if (ObjectUtils.isEmpty(gid)){
            throw new NullPointerException("输入的商品编号为空");
        }
        PdGoodsType goodsType = super.baseMapper.selectById(gid);
        return goodsType;
    }
}
